//
// Created by zain on 2017/3/14.
//

#include "Camera.h"

using namespace ZainGL;
using namespace glm;

glm::mat4 Camera::getViewMatrix() {
    return mTransform;
}

void Camera::setFocusOnPosition(const vec3 &focusOnPosition) {
    mFocusOnPosition = focusOnPosition;
    mTransform = lookAt(getPosition(), mFocusOnPosition, WORLD_UP);
}

void Camera::setPosition(const glm::vec3 &position) {
    if (mFocusOnPosition == vec3()) {
        Object::setPosition(position);
    } else {
        mTransform = lookAt(position, mFocusOnPosition, WORLD_UP);
    }
}

vec3 Camera::getPosition() {
    //return mPosition;
    return inverse(mTransform)[3];
}

vec3 Camera::getForward() {
    //mViewForward=normalize(mFocusOnPosition - mPosition);
    return inverse(mTransform)[2];
}

vec3 Camera::getUp() {
    //mViewUp=normalize(cross(mViewForward, mViewRight));
    return inverse(mTransform)[1];
}

vec3 Camera::getRight() {
    //mViewRight=normalize(cross(WORLD_UP, mViewForward));
    return inverse(mTransform)[0];
}

const vec3 &Camera::getFocusOnPosition() const {
    return mFocusOnPosition;
}
